package es.udc.pfc.davidparedes.model.director;

import java.util.Calendar;
import java.util.List;

import org.springframework.stereotype.Repository;

import es.udc.pfc.davidparedes.model.dao.GenericDaoHibernate;

@Repository("directorDao")
public class DirectorDaoHibernate extends
		GenericDaoHibernate<Director, Long> implements DirectorDao {
	
	@SuppressWarnings("unchecked")
	public List<Director> findDirectorsByStore(Long storeId) {
		
		Calendar now = Calendar.getInstance();
		return getSession()
				  .createQuery(
				  "SELECT d FROM Director d WHERE "
				  + "(d.deletionDate is null or d.deletionDate > :now) "
				  + "AND d.store.storeId = :storeId")
				  .setParameter("storeId", storeId)
				  .setCalendar("now", now)
				  .list();
	}
	
}